package com.zzusedating.androidapp.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zzusedating.androidapp.R;
import com.zzusedating.androidapp.customlayout.SpinnerWithTitle;
import com.zzusedating.androidapp.model.Favour;
import com.zzusedating.androidapp.tools.MyApplication;

import org.json.JSONException;
import org.json.JSONObject;

public class MateIntentFragment extends Fragment {
    private SpinnerWithTitle age;
    private SpinnerWithTitle res;
    private SpinnerWithTitle edubg;
    private SpinnerWithTitle major;
    private SpinnerWithTitle height;
    private SpinnerWithTitle weight;
    private SpinnerWithTitle orgtype;
    private SpinnerWithTitle monthSalar;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mate_intent_layout, container, false);
        age= view.findViewById(R.id.Condition_AgeSWT);
        res= view.findViewById(R.id.Condition_ResidenceSWT);
        edubg= view.findViewById(R.id.Condition_EduBg);
        major= view.findViewById(R.id.Condition_Major);
        height= view.findViewById(R.id.Condition_Height);
        weight= view.findViewById(R.id.Condition_Weight);
        orgtype= view.findViewById(R.id.Condition_OrgType);
        monthSalar= view.findViewById(R.id.Condition_MonthlyIncome);
        return view;
    }
    public void setData(JSONObject data){
        // todo init view and init data
    }
    public JSONObject getData(){
        JSONObject jsonObject = new JSONObject();
        try {
            short tmp = 0;
            Favour favour = new Favour(MyApplication.getBasicProfile().getInt("userId"),
                   tmp, "China", "Han", tmp, res.getSelection(), edubg.getSelectionIndexShort(),
                    major.getSelection(), height.getSelectionIndexShort(), weight.getSelectionIndexShort(),
                    tmp, tmp, orgtype.getSelectionIndexShort(), monthSalar.getSelectionIndexShort());
            jsonObject = new JSONObject(new Gson().toJson(favour, new TypeToken<Favour>(){}.getType()));
            return jsonObject;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }
}
